﻿using M_Purchase.Api.Appliction.Command.PurchCommand;
using M_Purchase.Domain;
using M_Purchase.Repository.PurchaseInterface;
using MediatR;

namespace M_Purchase.Api.Appliction.CommandHandlers.PurchCommandHandler
{
    /// <summary>
    /// 根据采购编号显示采购信息
    /// </summary>
    public class GetPurcehidCommandHandler : IRequestHandler<GetPurcehidCommand, List<Purch>>
    {
        private readonly IPurchRepository _purchRepository;
        public GetPurcehidCommandHandler(IPurchRepository purchRepository)
        {
            _purchRepository = purchRepository;
        }
        public async Task<List<Purch>> Handle(GetPurcehidCommand request, CancellationToken cancellationToken)
        {
             
            var ss = await _purchRepository.GetModelsAsync(request.PurchaseID);
            ss.InventoryState = "已入库";
            ss.InventoryNo ="CK"+ DateTime.Now.ToString("yyyyMMddHHmm");
           await _purchRepository.UpdateAsync(ss);
            return await _purchRepository.GetAsync(d => d.PurchaseID == request.PurchaseID);
        }
    }
}
